package com.travelsmart.server.integration;

import java.util.ArrayList;
import java.util.List;

import com.smart.hotelsmart.InfoHotelResponseType;
import com.smart.hotelsmart.RoomType;
import com.travelsmart.client.bean.to.HotelTO;
import com.travelsmart.client.bean.to.QuartoTO;

public class BuilderHotelTO {
	
	
	public HotelTO criarHotelTO(InfoHotelResponseType response) {
		HotelTO to = new HotelTO();
		to.setNome(response.getNameHotel());
		to.setLinkSelection(response.getLinkSelection());
		to.setCodigo(response.getCodeHotel());
		to.setCep(response.getCep());
		to.setCidade(response.getCidade());
		to.setEndereco(response.getEndereco());
		to.setLatitude(response.getLatitude());
		to.setLongitude(response.getLongitude());
		to.setQualidade(response.getQuality());
		to.setListRoom(new ArrayList<QuartoTO>());
		
		
		List<RoomType> rooms = response.getListRoom().getRoom();
		for (RoomType room : rooms) {
			to.getListRoom().add(criarQuartoTO(room));
		}
		List<String> images = response.getListImage().getImage();
		to.setListImages(images);
		return to;
	}

	
	private QuartoTO criarQuartoTO(RoomType room){
		assert room != null;
		assert room.getId() != 0;
		QuartoTO rto = new QuartoTO();
		rto.setCodigoQuarto(room.getCodeRoom());
		rto.setDescricao(room.getDescription());
		rto.setDetalhes(room.getDetails());
		rto.setImagens(room.getImage());
		rto.setInfo(room.getInfo());
		rto.setNome(room.getName());
		rto.setPreco(room.getPrice());
		rto.setQtiDisponivel(room.getAmountAvailable());
		return rto;
		
	}

}
